package com.xyh.transaction.controller;

import com.github.pagehelper.PageInfo;
import com.xyh.transaction.entity.dto.role.RoleEditOrAddDto;
import com.xyh.transaction.entity.dto.role.RolePageDto;
import com.xyh.transaction.entity.dto.user.ArrDto;
import com.xyh.transaction.entity.dto.user.ChangeDto;
import com.xyh.transaction.entity.vo.RoleStatusVo;
import com.xyh.transaction.entity.vo.RoleVo;
import com.xyh.transaction.response.ResponseResult;
import com.xyh.transaction.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @ApiOperation(value = "角色列表", notes = "返回所有的角色")
    @PostMapping("list")
    public ResponseResult<PageInfo<RoleVo>> roleList(@RequestBody RolePageDto rolePageDto) {
        PageInfo<RoleVo> roleList = roleService.getRoleList(rolePageDto);
        return ResponseResult.success("查询成功！", roleList);
    }


    @ApiOperation(value = "状态列表", notes = "返回所有状态")
    @GetMapping("status")
    public ResponseResult<Set<RoleStatusVo>> statusList() {
        Set<RoleStatusVo> statusList = roleService.getRoleStatusList();
        return ResponseResult.success("查询成功！", statusList);
    }

    @ApiOperation(value = "更改角色状态", notes = "根据id修改角色状态")
    @PostMapping("change")
    public ResponseResult<Void> change(@RequestBody ChangeDto changeDto) {
        roleService.changeStatus(changeDto);
        return ResponseResult.success("操作成功！", null);
    }

    @ApiOperation(value = "修改角色信息",notes = "根据id修改角色信息")
    @PostMapping("edit")
    public ResponseResult<Void> edit (@RequestBody RoleEditOrAddDto roleEditOrAddDto)  {
        roleService.updateRole(roleEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "添加角色",notes = "添加新的角色")
    @PostMapping("add")
    public ResponseResult<Void> add (@RequestBody RoleEditOrAddDto roleEditOrAddDto){
        roleService.addRole(roleEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "删除角色", notes = "根据id删除角色")
    @PostMapping("delete")
    public ResponseResult<Void> delete(@RequestBody ArrDto arrDto) {
        roleService.deleteRole(arrDto);
        return ResponseResult.success("操作成功！", null);
    }

}
